import { get } from './request'
import router from '../router/index'

const whitelist = [
  '/signin'
]

router.beforeEach(async (to, from, next) => {
  if (whitelist.indexOf(to.path) !== -1) {
    next()
  } else {
    const result = await get({
      url: '/users/auth'
    })

    if (result.data.ret) {
      next()
    } else {
      next({path: '/signin'})
    }
  }
})